// TmSetting.cpp : implementation file
//

#include "stdafx.h"
#include "UsbPhTest.h"
#include "TmSetting.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTmSetting dialog


CTmSetting::CTmSetting(CWnd * pwndtxt, CWnd* pParent /*=NULL*/)
	: CDialog(CTmSetting::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTmSetting)
    m_oTime = CTime::GetCurrentTime();
    m_oDate = CTime::GetCurrentTime();
	//}}AFX_DATA_INIT
    m_pWndtxt = pwndtxt;
}


void CTmSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTmSetting)
	DDX_DateTimeCtrl(pDX, IDC_DATE, m_oDate);
	DDX_DateTimeCtrl(pDX, IDC_TIME, m_oTime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTmSetting, CDialog)
	//{{AFX_MSG_MAP(CTmSetting)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_TIME, OnDatetimechangeTime)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATE, OnDatetimechangeDate)
	ON_BN_CLICKED(IDC_BTN_SETTIME, OnBtnSettime)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTmSetting message handlers

void CTmSetting::OnDatetimechangeTime(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	this->UpdateData();
    ChangeTime();
	*pResult = 0;
}

void CTmSetting::OnDatetimechangeDate(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	this->UpdateData();	
    ChangeTime();
	*pResult = 0;
}

void CTmSetting::ChangeTime(void)
{
    CTime dt(m_oDate.GetYear(), m_oDate.GetMonth(), m_oDate.GetDay(),
        m_oTime.GetHour(), m_oTime.GetMinute(), m_oTime.GetSecond() );
    m_dtTime = dt;
    CString str;
    str.Format("%02X %02X %02X %02X %02X", dt.GetYear()-2000, dt.GetMonth(), dt.GetDay(), 
        dt.GetHour(), dt.GetMinute() );
    if( m_pWndtxt )
        m_pWndtxt->SetWindowText(str);  
}

void CTmSetting::OnBtnSettime() 
{
	// TODO: Add your control notification handler code here
	ChangeTime();
    ::AfxGetMainWnd()->PostMessage(WM_SHOW_MAIN,0, 0);        
}
